var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    topTabItems: ["视频", "军事", "篮球"],
    videoDataList: [],  //视频数据
    SoderDataList: [],  //军事数据
    BakbooDataList: [],  //篮球数据
    currentTopItem: 0,
    swiperHeight: 0,
    types: 0,  //顶部tab项ID
    scrollTop:0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.mangerViewData();
  },

  /**
   * 事件处理
   */
  mangerViewData: function () {
    var that = this;
    switch (that.data.types) {
      //视频
      case 0:
        that.setSwiperData();
        return
      //军事
      case 1:
        that.setSwiperData();
        return
      //篮球
      case 2:
        that.setSwiperData();
        return
      default:
        break;
    }
    return false;
  },

  /**
   * 设置视频数据
   */
  setSwiperData: function () {
    var that = this;
    //视频
    if (that.data.types == 0) {
      // for (var i = 0; i < 30; i++) {
      //   that.data.videoDataList.push('视频' + i);
      // }
      that.setData({
        videoDataList: that.data.videoDataList
      })
    }
    //军事
    if (that.data.types == 1) {
      for (var i = 0; i < 30; i++) {
        that.data.SoderDataList.push('军事' + i);
      }
      that.setData({
        SoderDataList: that.data.SoderDataList
      })
    }
    //篮球
    if (that.data.types == 2) {
      for (var i = 0; i < 30; i++) {
        that.data.BakbooDataList.push('篮球' + i);
      }
      that.setData({
        BakbooDataList: that.data.BakbooDataList
      })
    }
  },

  /**
   * 点击顶部bar 切换顶部标签
   */
  switchTab: function (e) {
    var that = this;
    this.setData({
      currentTopItem: e.currentTarget.dataset.idx,
      types: e.currentTarget.dataset.idx
    });
    //如果需要加载数据
    that.mangerViewData();
  },

  /**
   * swiperChange
   */
  bindChange: function (e) {
    var that = this;
    that.setData({
      currentTopItem: e.detail.current,
      types: e.detail.current
    });

    //如果需要加载数据
    that.mangerViewData();
  },

  /**
   * 加载更多操作
   */
  loadMoreData: function () {
    var that = this;
    console.log("上啦加载更多");
    setTimeout(function () {
      that.setSwiperData();
    }, 500)
  },

  /**
   * 下拉刷新
   */
  refresh: function (e) {
    
  },

  /**
   * 下拉距离
   */
  scroll: function (event) {
    var that = this;
    that.setData({
      scrollTop: event.detail.scrollTop
    });
  },  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          swiperHeight: (res.windowHeight - 37)
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})